package com.wc.alorithm_blue_bridge_history.littlewhite.Q231227.Q10015;

import java.util.Scanner;

/**
 * @Author congge
 * @Date 2023/12/27 21:47
 * @description
 */
public class Main2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t-- > 0) {
            int n = sc.nextInt();
            String s = sc.next();
            boolean[][] map = new boolean[n + 1][n + 1];
            for (int i = 1; i < n; i++) {
                int u = sc.nextInt();
                int v = sc.nextInt();
                map[u][v] = true;
                map[v][u] = true;
            }
            char[] color = new char[n + 1];
            for (int i = 0; i < n; i++) {
                color[i + 1] = s.charAt(i);
            }
            boolean flg = false;
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= n; j++) {
                    if (i == j) {
                        continue;
                    }
                    for (int k = 1; k <= n; k++) {
                        if (j == k || i == k) {
                            continue;
                        }
                        if (map[i][j] && map[i][k]) {
                            if (color[i] == color[j] && color[j] == color[k]) {
                                flg = true;
                            }
                        }
                    }
                }
            }
            if (flg){
                System.out.println("NO");
            }else {
                System.out.println("YES");
            }
        }
    }
}
